
Khan S. Alam 18 https://E-next.in
Postorder:
In contrastwith preorder traversal, whichvisits theroot first, postorder traversal
visits the root last. To do a postorder traversal of ageneraltree:
1. Do a postordertraversal each of thesubtrees of the root one-by-one in theorder
given; &then
2. Visit the root.
Algorithm Postfix (Postorder)TreeTraversal:
Print the postfix expression for anexpression tree.
Pre tree is a pointer to an expression tree.
Post the postfix expression has beenprinted
1. if (treenotempty)
i. postfix (tree left subtree)
ii. postfix (tree right subtree)
iii. print (tree token)
2. end if
end postfix
Inorder:
Inorder traversal only makes sensefor binarytrees. Whereas preorder traversal
visits the root first and postorder traversalvisits theroot last, inorder traversalvisits the
root in between visiting the left and right subtrees:
1. Traversethe left subtree; &then
2. Visit the root; &then
3. Traversethe right subtree.
Algorithm Infix(Inorder)TreeTraversal:
Print the infix expression for an expression tree.
Pre tree is a pointer to an expression tree.
Post thepostfix expression has beenprinted
1. if (treenotempty)
i. prefix (treeleft subtree)
ii. print (tree token)
iii. prefix (treeright subtree)
2. end if
end infix
Notationsof the tree:
Preorder:Z X WPVYU QT RNS
Postorder:PWV XQU NRS TYZ
Inorder: PWX VZQ U YNRT S